package com.liyong.bos.controller;

import com.liyong.bos.domain.WeatherInfo;
import com.liyong.bos.service.GetWeatherService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by ApacheMoy on 2017/4/20.
 */
@Controller
@RequestMapping(value = "/weather")
public class GetWeatherController {
    @Autowired
    private GetWeatherService getWeatherService;

    @RequestMapping(value = "/weatherInfo", method = RequestMethod.POST)
    public @ResponseBody
    WeatherInfo getWeatherData(String cityName) {
        System.out.println("-------------");
        WeatherInfo weatherInfo =new WeatherInfo();
        if (StringUtils.isNotBlank(cityName)) {
            weatherInfo = getWeatherService.getWeatherByCityName(cityName);
        } else {
            weatherInfo = getWeatherService.getWeatherByCityName("长沙");
        }
        return weatherInfo;
    }
}
